<template>
  <el-dialog
    class="dialog"
    v-dialogDrag
    :visible="isDialogVisible"
    center
    :append-to-body="true"
    :close-on-click-modal="false"
    @close="closeEdit"
    :width="width"
  >
    <dialogHeader slot="title" :title="titleName" :style-type="$store.state.app.dialogType" />
    <div>
      <calendar-select-component></calendar-select-component>
    </div>
  </el-dialog>
</template>

<script>
import dialogHeader from '@/components/dialogHeader'
import OneTableTemplate from '@/components/templates/oneTable';
import CalendarSelectComponent from './calendarSelectComponent.vue';
import { orgApis } from '@/api/apiList/org'
import moment from 'moment'

// import { setDynamicFieldsData } from '@/utils/dataOperation'
// import { testApis } from '@/api/graphQLApiList/test'
export default {
  components: {
    dialogHeader,
    OneTableTemplate,
    CalendarSelectComponent
  },
  props: {
    width: {
      type: String,
      default: '1200px'
    },
    isDialogVisible: {
      type: Boolean,
      default: false
    },
    dataForForm: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      VINtitleName:'VIN码选择',
      titleName: '订货日历编辑',
      VINShow:false,
      refreshTableKey: '0',
      // table表格查询API配置对象
      dynamicApiConfig: orgApis.stoTransferInstructionQueryByPage,
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '日历名称：',
              codeField: 'apiCode',
              isRequire: true,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey2',
              labelName: '日历年份：',
              codeField: 'apiName',
              isRequire: true,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey3',
              labelName: '状态：',
              codeField: 'isEnable',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '启用' },
                { statusId: '0', statusText: '禁用' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: true
            }
          ],
      // form 的表单对象
      formField: this.$utils.getFormField(
        this,
        {
          apiCode: '',
          apiName: ''
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
      // 动态组件-按钮
      dynamicButtons:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons
          : [
            {
              compKey: 'btnKey1',
              type: 'primary',
              size: 'small',
              name: '',
              clickEvent: () => this.queryTable(1),
              text: '增加网点',
              position: 'left'
            },
            {
              compKey: 'btnKey1',
              type: 'primary',
              size: 'small',
              name: '',
              clickEvent: () => this.queryTable(1),
              text: '删除网点',
              position: 'left'
            },
            {
              compKey: 'btnKey1',
              type: 'primary',
              size: 'small',
              name: '',
              clickEvent: () => this.queryTable(1),
              text: '工作日全选',
              position: 'left'
            },
            {
              compKey: 'btnKey1',
              type: 'primary',
              size: 'small',
              name: '',
              clickEvent: () => this.queryTable(1),
              text: '周六全选',
              position: 'left'
            },
            {
              compKey: 'btnKey1',
              type: 'primary',
              size: 'small',
              name: '',
              clickEvent: () => this.queryTable(1),
              text: '周日全选',
              position: 'left'
            },
            {
              compKey: 'btnKey2',
              type: '',
              size: 'small',
              icon: '',
              clickEvent: () => this.vinSelect(),
              text: '保存',
              position: 'right'
            },
            {
              compKey: 'btnKey3',
              type: '',
              size: 'small',
              icon: '',
              clickEvent: () => this.closeEdit(1),
              text: '取消',
              position: 'right'
            }
          ],
      // 动态组件-表格网格列
      dynamicTableCols:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols : [
            {
              prop: 'orgName',
              label: '电池包'
            },
            {
              prop: 'orgName',
              label: 'VIN'
            },
            {
              prop: 'orgName',
              label: '车型配置'
            }
          ],
      // 字段格式化转换（用于导出excel）（kvs表示键值转换）
      dynamicExportConverts: {
        isEnable: {
          convert: 'kvs',
          kvs: {
            '1': '是',
            '0': '否'
          }
        }
      },
      // 单表格模版页面组件回调事件
      callbackObj: {
        // 当选择项发生变化时会触发该事件（多选时）
        onCheckSelectChange: (selection) => {
          this.handleSelectionChange(selection)
        }
      }
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    // form表单组件每个元素所占栅格栏数每行24格
    spanNum() {
      return 24
    },
    vinSelect () {
      this.VINShow = true
      this.VINtitleName = "VIN码选择"
    },
    // 关闭弹窗
    closeEdit() {    
      this.$emit('close')
    },
    VINClose (type) {
       this.VINShow = false
    },

    // 表单数据初始化
    initData() {
      // if (JSON.stringify(this.dataForForm) === '{}') {
      //   this.titleName = '新增'
      //   this.dynamicFieldsData.senceCode = 'Ｘ'
      //   return
      // } else {
      //   this.titleName = '修改'
      //   this.dynamicFieldsData.id = this.dataForForm.id
      //   this.dynamicFieldsData.updateControlId = this.dataForForm.updateControlId
      //   this.dynamicFormFields.forEach((item) => {
      //     if (item.label === '接口编码') {
      //       item.disabled = true
      //     }
      //   })
      //   this.queryById()
      // }
    },

    // 编辑表单详情数据查询
    queryById() {
    //   const that = this
    //   const saveObj = { id: this.dataForForm.id }
    //   const apiQueryRow = ['apiCode', 'apiName']
    //   that.$utils.apiRrequest(that, 'mutation', testApis.dbSenceApiQueryFindObjectById, saveObj, (data) => {
    //     if (data) {
    //       const resultData = data.data[testApis.dbSenceApiQueryFindObjectById.ServiceCode].rows
    //       setDynamicFieldsData(this.dynamicFieldsData, resultData)
    //     }
    //   }, apiQueryRow)
    },

    // 保存
    save() {
    //   const that = this
    //   this.$refs['multipleForm'].$children[0].validate(valid => {
    //     if (valid) {
    //       that.$utils.apiRrequest(that, 'mutation', testApis.dbSenceApiMutationSaveObject, this.dynamicFieldsData, (data) => {
    //         if (data) {
    //           that.$message({
    //             message: '保存成功',
    //             type: 'success',
    //             duration: 2000
    //           })
    //           this.closeEdit(1)
    //         }
    //       })
    //     }
    //   })
    }

    // 重置
    // resetData() {
    //   const that = this
    //   this.dynamicFormFields.forEach((e, i) => {
    //     that.dynamicFieldsData[e.codeField] = ''
    //   })
    //   if (JSON.stringify(this.dataForForm) !== '{}') {
    //     this.dynamicFieldsData.apiCode = this.dataForForm.apiCode
    //   }
    //   this.$refs['multipleForm'].$children[0].clearValidate()
    // }
  }
}
</script>
<style scoped>
.dialog{
  height:633px !important;
  margin-top:-20px !important;
}
</style>